// component/visitorsAll/com/visitor-tools/visitor-tools.js
import api from "./../../../../common/api.js";
const app = getApp();

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  options: {
    styleIsolation: 'isolated',
    pureDataPattern: /^_/
  },

  /**
   * 组件的初始数据
   */
  data: {
    banners: [],
    navs: [{
      param: 'poster',
      title: '营销海报',
      subtitle: '好房需要包装',
      icon: 'icon-yingxiaohaibao',
      iconColor: 'F0B56B',
      tag: '推荐',
      handle: 'jumpToVisitorToolsList',
      isAuth: true,
    }, {
      param: 'wxPublicity',
      title: '微信推广',
      subtitle: '经纪人营销群',
      icon: 'icon-weixin',
      iconColor: '71CEB1',
      handle: 'jumpToPickHouseList',
      isAuth: true,
    }, {
      param: 'pyqPublicity',
      title: '朋友圈推广',
      subtitle: '获取朋友圈商机',
      icon: 'icon-pengyouquan',
      iconColor: '93AED1',
      handle: 'jumpToPickHouseList',
      isAuth: true,
    }, {
      param: 'card',
      title: '个性名片',
      subtitle: '您的个性名片',
      icon: 'icon-mingpian',
      iconColor: 'A9A5F1',
      tag: '推荐',
      handle: 'jumpToVisitorToolsList',
      isAuth: true,
    }, {
      param: 'phrase',
      title: '营销短文',
      subtitle: '好房如何推广',
      icon: 'icon-yingxiaoduanwen',
      iconColor: 'EC9292',
      handle: 'jumpToVisitorToolsList',
      isAuth: true,
    }, 
    // {
    //   param: '',
    //   title: '多房源分享',
    //   subtitle: '分享一套怎么够',
    //   icon: 'icon-gengduo2',
    //   iconColor: 'FFCDAA',
    //   handle: '',
    //   isAuth: true,
    // }
  ]
  },

  /**
   * 组件的监听器
   */
  observers: {

  },

  /**
   * 组件的生命周期
   */
  lifetimes: {
    attached: function () {
      let t = this;
      t.loadBanner()

    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //获客工具-- 点击轮播图
    onClickBanner(e) {
      let t = this;
      let handle = e.currentTarget.dataset.handle || ''
      let param = e.currentTarget.dataset.param || ''
      if (!handle) return
      t[handle](param)
    },

    onClickNav(e) {
      let t = this;
      let handle = e.currentTarget.dataset.handle || ''
      let param = e.currentTarget.dataset.param || ''
      let isAuth = e.currentTarget.dataset.auth || false
      if (!handle) return
      if (isAuth) {
        app.mobileLogin()
          .then(() => {
            t[handle](param)
          })
          .catch(() => {
            app.globalData.afterMobileAuthorCallBack = () => {
              t[handle](param, 'redirectTo')
            };
          })
      } else {
        t[handle](param)
      }
    },

    jumpToWebView(url) {
      if (!url) return
      wx.navigateTo({
        url: `/pages/webView/webView?webViewUrl=${url}`
      })
    },

    jumpToVisitorToolsList(target, method = 'navigateTo') {
      wx[method]({
        url: `/pages/visitors/tools/list/visitorToolsList?target=${target}`
      })
    },

    jumpToPickHouseList(target, method = 'navigateTo') {
      wx[method]({
        url: `/pages/home/pickHouseList/pickHouseList?option=${target}`
      })
    },
    // 获客工具-- 获取轮播图数据
    loadBanner() {
      let t = this
      api.getOperateList({
        pageType: "CUSTOMERSPAGE"
      }, (res) => {
        let list = res.data.content.rows || [];
        let banners = list.map((item) => {
          return {
            img: item.imgUrl || '',
            handle: 'jumpToWebView',
            param: item.linkUrl || ''
          }
        })
        t.setData({
          banners,
        });
      });
    },


  }
})